package yuekao2.util;

import org.wltea.analyzer.core.IKSegmenter;
import org.wltea.analyzer.core.Lexeme;

import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;

public class MyIkmoeney {
    public static ArrayList<String> Splitword(String str){
        //创造一个集合
        ArrayList<String> list = new ArrayList<>();
        //进行数据初始化
        StringReader stringReader = new StringReader(str);
        //IK词库
        IKSegmenter ikSegmenter = new IKSegmenter(stringReader, true);

        try {
            //获取下一个词元
            Lexeme next = ikSegmenter.next();
            //判断下一个词元是否是空
            if(next!=null){
                //方法返回当前词元的实际文本内容。
                String lexemeText = next.getLexemeText();
                //赋值
                list.add(lexemeText);
                //再次判断下一个循环
                next=ikSegmenter.next();
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return list;
    }

    public static void main(String[] args) {
        ArrayList<String> oo = MyIkmoeney.Splitword("你是一个大傻子");
        for (String s : oo) {
            System.out.println(s);
        }
    }
}
